<template>
  <div class="external" v-loading="loading">
    <div class="first">
      <div class="first-top">
        <div class="top-list" v-for="(item, index) in 6" :key="index">
          <div class="list-title">
            {{
              index == 0
                ? "姓名"
                : index == 1
                ? "电话"
                : index == 2
                ? "商户号"
                : index == 3
                ? "卡号"
                : index == 4
                ? "状态"
                : index == 5
                ? "单号"
                : ""
            }}
          </div>
          <div class="list-input">
            <el-input
              v-if="index == 0"
              v-model="firstName"
              clearable
              placeholder="请输入姓名"
            ></el-input>
            <el-input
              v-if="index == 1"
              v-model="firstPhone"
              clearable
              placeholder="请输入电话"
            ></el-input>
            <el-input
              v-if="index == 2"
              v-model="firstCommercial"
              clearable
              placeholder="请输入商户号"
            ></el-input>

            <el-input
              v-if="index == 3"
              v-model="firstCart"
              clearable
              placeholder="请输入卡号"
            ></el-input>

            <el-select
              v-if="index == 4"
              v-model="firstStatus"
              clearable
              placeholder="请选择状态"
            >
              <el-option
                v-for="item in firstStatusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>

            <el-input
              v-if="index == 5"
              v-model="firstOrderOdd"
              clearable
              placeholder="请输入单号"
            ></el-input>
          </div>
        </div>
      </div>

      <div class="first-top">
        <div class="top-list1">
          <div class="list-title">时间</div>
          <div class="list-input">
            <el-date-picker
              v-model="firstTime"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </div>
        </div>

        <div class="top-button">
          <div
            class="button"
            v-for="(item, index) in 2"
            :key="index"
            @click="externalFunction(index)"
          >
            {{ index == 0 ? "搜索" : "重置" }}
          </div>
        </div>
      </div>

      <div class="first-bottom">
        <img class="bottom-img" src="../../assets/index/icon-10.png" alt="" />
        <div class="bottom-title">已选择{{ multipleSelectionTotal }}项</div>
        <div class="bottom-title">
          服务调用总计：{{ multipleSelectionPrice }}元
        </div>
        <div
          class="bottom-title"
          style="color: #2588fa; text-decoration: underline; cursor: pointer"
          @click.stop="emptyStop"
        >
          清空
        </div>
      </div>
    </div>

    <div class="second">
      <div class="second-table">
        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          :header-cell-style="{
            color: '#949494',
            backgroundColor: '#F9F9F9',
          }"
          @sort-change="sortChange"
        >
          <!-- 自定义暂无数据 -->
          <template slot="empty">
            <div class="empty-block">
              <img
                class="empty-block-img"
                src="../../assets/common/common-empty.png"
              />
              <div class="empty-block-text">暂无数据～</div>
            </div>
          </template>
          <el-table-column
            type="selection"
            width="100"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="userId"
            label="用户id"
            width="200"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="merchantNo"
            label="商户号"
            width="200"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="orderNum"
            label="订单号"
            width="200"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="payCode"
            label="支付单号"
            width="200"
            align="center"
          >
          </el-table-column>
          <el-table-column label="状态" width="100" align="center">
            <template slot-scope="scope">
              <div
                :style="{
                  color:
                    scope.row.status == 0
                      ? '#2588FA'
                      : scope.row.status == 1
                      ? '#1DC225'
                      : '',
                }"
              >
                {{
                  scope.row.status == 0
                    ? "申请中"
                    : scope.row.status == 1
                    ? "成功"
                    : scope.row.status == 2
                    ? "转账中"
                    : scope.row.status == 3
                    ? "转账失败"
                    : ""
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="类型" width="100" align="center">
            <template slot-scope="scope">
              <div :style="{ color: scope.row.type == 1 ? '#1DC225' : '' }">
                {{
                  scope.row.type == 1
                    ? "转账"
                    : scope.row.type == -1
                    ? "提现"
                    : ""
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="" label="金额" width="180" align="center">
            <template slot-scope="scope"> ￥{{ scope.row.money }} </template>
          </el-table-column>
          <el-table-column prop="name" label="姓名" width="150" align="center">
          </el-table-column>
          <el-table-column prop="phone" label="电话" width="150" align="center">
          </el-table-column>

          <el-table-column
            prop="bank_name"
            label="银行名称"
            width="150"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="bank_number"
            label="银行卡号"
            width="280"
            align="center"
          >
          </el-table-column>
          <el-table-column prop="" label="消息" width="230" align="center">
            <template slot-scope="scope">
              <div
                :style="{ color: scope.row.message == null ? '' : '#1DC225' }"
                style="padding: 10px; box-sizing: border-box"
              >
                {{ scope.row.message == null ? "无消息" : scope.row.message }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="创建时间"
            sortable
            width="300"
            align="center"
          >
          </el-table-column>
        </el-table>
      </div>

      <div class="second-pagination">
        <div class="pagination-left">共{{ totalNum }}条数据</div>

        <div class="pagination-right">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 30, 50, 100, 200]"
            :page-size="10"
            layout="sizes, prev, pager, next, jumper"
            :total="totalNum"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getUserInfoWalletTransferOrder } from "../../api/order";

export default {
  data() {
    return {
      //--------第一区域
      firstName: "",
      firstPhone: "",
      firstCommercial: "",
      firstTime: [],
      // 用户时间输入框的时候起始值
      firstTimeA: "",
      // 用户时间输入框的时候结尾值
      firstTimeB: "",
      firstCart: "",
      firstStatus: "",
      firstStatusOptions: [
        {
          label: "申请中",
          value: 0,
        },
        {
          label: "成功",
          value: 1,
        },
        {
          label: "转账中",
          value: 2,
        },
        {
          label: "转账失败",
          value: 3,
        },
      ],
      firstOrderOdd: "",
      //------------第二区域
      tableData: [],
      multipleSelection: [],
      multipleSelectionTotal: 0,
      multipleSelectionPrice: 0,
      orderByType: 0,
      totalNum: 0,
      page: 1,
      limit: 10,
      loading: false,
    };
  },
  created() {
    this.getUserInfoWalletTransferOrderMet();
  },
  methods: {
    //----------订单
    getUserInfoWalletTransferOrderMet() {
      let params = {
        name: this.firstName, // 姓名
        phone: this.firstPhone, // 手机号
        createStartTime: this.firstTimeA,
        createEndTime: this.firstTimeB,
        bank_number: this.firstCart, // 卡号
        status: this.firstStatus, // 状态
        orderNum: this.firstOrderOdd, // 单号
        merchantNo: this.firstCommercial, // 商户号
        orderByType: this.orderByType, //  1 正序
        wtype: 1, // 外部
        pageNo: this.page,
        pageSize: this.limit,
      };

      getUserInfoWalletTransferOrder(params).then((res) => {
        if (res.resultStatus == true) {
          this.tableData = res.resultData.list;
          this.totalNum = res.resultData.totalNum;

          this.loading = false;
        }
      });
    },

    externalFunction(index) {
      this.loading = true;

      if (index == 0) {
        if (this.firstTime != null) {
          this.firstTimeA = this.firstTime[0];
          this.firstTimeB = this.firstTime[1];
        } else {
          this.firstTimeA = "";
          this.firstTimeB = "";
        }

        this.$nextTick(() => {
          this.getUserInfoWalletTransferOrderMet();
        });
      } else {
        this.firstName = "";
        this.firstPhone = "";
        this.firstCommercial = "";
        this.firstTime = [];
        this.firstTimeB = "";
        this.firstTimeA = "";
        this.firstCart = "";
        this.firstStatus = "";
        this.firstOrderOdd = "";
        this.orderByType = 0;
        this.multipleSelectionTotal = 0;

        this.$nextTick(() => {
          this.getUserInfoWalletTransferOrderMet();
        });
      }
    },
    // 表格区域点击选中 勾选对应的
    handleSelectionChange(val) {
      console.log("点击勾选", val);
      let price = 0;

      val.forEach((item, index) => {
        price = Number(price) + Number(item.money);
      });

      this.multipleSelectionTotal = val.length;
      this.multipleSelectionPrice = price;
      this.multipleSelection = val;
    },
    // 点击监听排序
    sortChange(e) {
      if (e.order == "ascending") {
        this.orderByType = 1;
      } else {
        this.orderByType = 0;
      }

      this.$nextTick(() => {
        this.getUserInfoWalletTransferOrderMet();
      });
    },
    //----------------------------------------------------------
    emptyStop() {
      this.multipleSelection = [];
      this.$refs.multipleTable.clearSelection();
      this.getUserInfoWalletTransferOrderMet();
    },
    //  查询当前页码多少条
    handleSizeChange(val) {
      this.limit = val;
      this.loading = true;
      this.getUserInfoWalletTransferOrderMet();
    },
    //  查询当前页
    handleCurrentChange(val) {
      this.page = val;
      this.loading = true;
      this.getUserInfoWalletTransferOrderMet();
    },
  },
};
</script>

<style lang="less" scoped>
.external {
  .first {
    .first-top {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      .top-list,
      .top-list1 {
        display: flex;
        align-items: center;
        margin-right: 12px;

        .list-title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #757575;
          margin-right: 12px;
        }

        .list-input {
          /deep/ .el-input__inner {
            width: 174px;
            height: 38px;
            background: #ffffff;
            border-radius: 4px;
          }
        }
      }

      .top-list:last-child {
        margin-right: 0;
      }

      .top-list1 {
        .list-input {
          /deep/ .el-input__inner {
            width: 400px;
            height: 38px;
            background: #ffffff;
            border-radius: 4px;
          }
        }
      }

      .top-button {
        display: flex;
        align-items: center;

        .button {
          width: 66px;
          height: 38px;
          background: #2588fa;
          border-radius: 4px;
          display: flex;
          align-items: center;
          justify-content: center;

          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #ffffff;
          cursor: pointer;
          border: 1px solid #2588fa;
        }

        .button:last-child {
          background: #ffffff;
          color: #949494;
          margin-left: 12px;
          border: 1px solid #dedede;
        }
      }
    }

    .first-bottom {
      margin-top: 16px;
      display: flex;
      align-items: center;
      height: 38px;
      background: #edf5ff;
      border-radius: 4px;
      border: 1px solid #aed4ff;
      padding: 0 16px;
      box-sizing: border-box;

      .bottom-img {
        width: 14px;
        height: 14px;
        margin-right: 11px;
      }

      .bottom-title {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #292929;
        margin-right: 17px;
      }
    }
  }

  .second {
    margin-top: 16px;
    .second-table {
      /deep/ .el-table thead {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #949494;
      }

      /deep/ .el-table tr {
        height: 46px;
      }

      /deep/ .el-table__empty-text {
        line-height: 0;
      }

      /deep/ .el-table .el-table__cell {
        padding: 0;
      }

      .empty-block {
        margin-top: 62px;
        padding-bottom: 40px;

        .empty-block-img {
          width: 130px;
          height: 130px;
          margin: 0 auto;
        }

        .empty-block-text {
          font-size: 12px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #999999;
          margin-top: 10px;
          height: 17px;
          line-height: 17px;
        }
      }

      .operation {
        display: flex;
        align-items: center;
        justify-content: center;

        .operation-list {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #2588fa;
          text-decoration: underline;
          cursor: pointer;
          margin-right: 16px;
        }
      }
    }

    .second-pagination {
      height: 75px;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .pagination-left {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 15px;
        color: #949494;
      }

      .pagination-right {
        /deep/ .el-pagination .btn-prev {
          padding: 0;
          width: 30px;
          height: 30px;
          background: #f4f5f9;
          border-radius: 2px;
          border: 1px solid #d9d9d9;
          margin-right: 8px;
        }

        /deep/ .el-pagination .btn-next {
          padding: 0;
          width: 30px;
          height: 30px;
          background: #f4f5f9;
          border-radius: 2px;
          border: 1px solid #d9d9d9;
        }

        /deep/ .el-pager li {
          padding: 0;
          width: 30px;
          height: 30px;
          border-radius: 2px;
          background: #f4f5f9;
          border: 1px solid #d9d9d9;
          line-height: 30px;
          margin-right: 8px;
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 15px;
          color: #949494;
        }

        /deep/ .el-pager li.active {
          background: #2588fa;
          color: #ffffff;
        }

        /deep/ .el-input--mini .el-input__inner {
          height: 30px;
          background: #f4f5f9;
        }

        /deep/ .el-input__inner {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: rgba(0, 0, 0, 0.65);
        }
      }
    }
  }
}
</style>
